package com.file;

import javax.swing.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class Test_3 {
    public static void main(String[] args) {
        input2();
    }
    public static void input(){
        String pathname="D:\\javacode\\javacode\\J2024_11_16\\hello.txt";
        int readdata=0;
        FileInputStream fileInputStream=null;
        try {
             fileInputStream = new FileInputStream(pathname);
            while((readdata= fileInputStream.read())!=-1){
                System.out.print((char)readdata);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            try {
                fileInputStream.close();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }


    public static void input2(){
        String pathname="D:\\javacode\\javacode\\J2024_11_16\\hello.txt";
        int readlen=0;
        FileInputStream fileInputStream=null;
        byte []buf=new byte[8];

        try {
            fileInputStream = new FileInputStream(pathname);
            while((readlen=fileInputStream.read(buf))!=-1){
                System.out.print(new String(buf,0,readlen));
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            try {
                fileInputStream.close();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }
}
